<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - HUAWEI Global Store</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {margin:0;padding:0;box-sizing:border-box;}
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: #f5f9ff;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            position: relative;
            overflow-x: hidden;
        }
        /* 背景装饰元素 */
        .background-decoration {
            position: absolute;
            width: 100%;
            height: 100%;
            z-index: -1;
            overflow: hidden;
        }
        .decoration-circle {
            position: absolute;
            border-radius: 50%;
            background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(30, 64, 175, 0.05) 100%);
        }
        .circle-1 { width: 300px; height: 300px; top: -100px; right: -100px; }
        .circle-2 { width: 200px; height: 200px; bottom: 50px; left: -50px; }
        .circle-3 { width: 150px; height: 150px; bottom: 200px; right: 30%; }

        .header {
            background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
            color: white;
            padding: 15px 0;
            box-shadow: 0 4px 20px rgba(0,0,0,0.1);
            position: relative;
            z-index: 10;
        }
        .header .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .logo {
            font-size: 28px;
            font-weight: bold;
            cursor: pointer;
            display: flex;
            align-items: center;
        }
        .logo-icon { margin-right: 10px; font-size: 32px; }
        .header a {
            color: white;
            text-decoration: none;
            margin-left: 25px;
            font-weight: 500;
            transition: all 0.3s ease;
            position: relative;
            padding: 5px 0;
        }
        .header a::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 0;
            height: 2px;
            background: white;
            transition: width 0.3s ease;
        }
        .header a:hover::after { width: 100%; }

        .login-container {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 40px 20px;
        }
        .login-box {
            background: white;
            padding: 40px;
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            width: 100%;
            max-width: 450px;
            text-align: center;
            position: relative;
            overflow: hidden;
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .login-box:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.12);
        }
        .login-box::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 6px;
            background: linear-gradient(90deg, #1e40af, #3b82f6, #60a5fa);
        }
        .login-box h2 {
            margin-bottom: 30px;
            font-size: 32px;
            color: #1f2937;
            font-weight: 700;
        }
        .input-group {
            position: relative;
            margin-bottom: 20px;
        }
        .input-group i {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #9ca3af;
            font-size: 18px;
        }
        .login-box input[type="text"],
        .login-box input[type="password"] {
            width: 100%;
            padding: 15px 15px 15px 45px;
            border: 2px solid #e5e7eb;
            border-radius: 12px;
            font-size: 16px;
            transition: all 0.3s ease;
        }
        .login-box input:focus {
            outline: none;
            border-color: #3b82f6;
            box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
        }
        /* 身份选择样式 */
        .identity-select {
            margin: 20px 0;
            display: flex;
            justify-content: center;
            gap: 30px;
            align-items: center;
        }
        .identity-option {
            display: flex;
            align-items: center;
            cursor: pointer;
        }
        .identity-option input {
            margin-right: 8px;
            accent-color: #3b82f6;
            width: 16px;
            height: 16px;
        }
        .identity-option label {
            color: #4b5563;
            font-size: 16px;
            transition: color 0.3s ease;
        }
        .identity-option:hover label {
            color: #3b82f6;
        }
        .identity-error {
            color: #ef4444;
            font-size: 14px;
            margin-top: -15px;
            margin-bottom: 15px;
            display: none;
        }

        .login-box .checkbox-container {
            margin: 20px 0;
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 14px;
            color: #4b5563;
        }
        .login-box .checkbox-container div {
            display: flex;
            align-items: center;
        }
        .login-box .checkbox-container input {
            margin-right: 8px;
            accent-color: #3b82f6;
        }
        .forgot-password {
            color: #3b82f6;
            text-decoration: none;
            transition: color 0.3s ease;
        }
        .forgot-password:hover {
            color: #1e40af;
            text-decoration: underline;
        }
        .login-box .btn {
            width: 100%;
            padding: 16px;
            border: none;
            border-radius: 12px;
            font-size: 17px;
            font-weight: 600;
            color: white;
            background: linear-gradient(135deg, #3b82f6, #1d4ed8);
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        .login-box .btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
            transition: left 0.7s ease;
        }
        .login-box .btn:hover::before { left: 100%; }
        .login-box .btn:hover {
            background: linear-gradient(135deg, #1d4ed8, #1e40af);
            transform: translateY(-3px);
            box-shadow: 0 10px 25px rgba(59, 130, 246, 0.4);
        }
        .divider {
            margin: 25px 0;
            position: relative;
            text-align: center;
            color: #6b7280;
        }
        .divider::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 0;
            width: 100%;
            height: 1px;
            background: #e5e7eb;
        }
        .divider span {
            background: white;
            padding: 0 15px;
            position: relative;
            z-index: 1;
        }
        .social-login {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-bottom: 25px;
        }
        .social-btn {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: #f3f4f6;
            color: #4b5563;
            font-size: 20px;
            transition: all 0.3s ease;
            cursor: pointer;
        }
        .social-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        .social-btn.wechat:hover { background: #2aae67; color: white; }
        .social-btn.qq:hover { background: #12b7f5; color: white; }
        .social-btn.weibo:hover { background: #e6162d; color: white; }
        .register-link {
            margin-top: 20px;
            font-size: 15px;
            color: #6b7280;
        }
        .register-link a {
            color: #3b82f6;
            text-decoration: none;
            font-weight: 600;
            margin-left: 5px;
            transition: color 0.3s ease;
        }
        .register-link a:hover {
            color: #1e40af;
            text-decoration: underline;
        }

        /* 响应式设计 */
        @media (max-width: 500px) {
            .login-box { padding: 30px 25px; }
            .login-box h2 { font-size: 26px; }
            .header .container { flex-direction: column; gap: 10px; }
            .header a { margin: 0 10px; }
            .identity-select { gap: 20px; }
        }

        /* 错误提示样式 */
        .error-message {
            color: #ef4444;
            font-size: 14px;
            text-align: left;
            margin-top: -10px;
            margin-bottom: 15px;
            display: none;
        }

        /* 加载动画 */
        .btn-loading {
            position: relative;
            color: transparent !important;
        }
        .btn-loading::after {
            content: '';
            position: absolute;
            width: 20px;
            height: 20px;
            top: 50%;
            left: 50%;
            margin: -10px 0 0 -10px;
            border: 3px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 0.8s ease infinite;
        }
        @keyframes spin { to { transform: rotate(360deg); } }

        /* 登录成功动画 */
        .login-success {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.9);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 1000;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.5s ease;
        }
        .success-content {
            text-align: center;
            background: white;
            padding: 40px;
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transform: scale(0.9);
            transition: transform 0.5s ease;
        }
        .success-icon {
            font-size: 60px;
            color: #10b981;
            margin-bottom: 20px;
        }
        .success-content h3 {
            font-size: 24px;
            margin-bottom: 10px;
            color: #1f2937;
        }
        .success-content p {
            color: #6b7280;
            margin-bottom: 20px;
        }
        .continue-btn {
            padding: 12px 25px;
            background: #3b82f6;
            color: white;
            border: none;
            border-radius: 8px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        .continue-btn:hover {
            background: #2563eb;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(59, 130, 246, 0.3);
        }
    </style>
</head>
<body>
    <!-- 背景装饰元素 -->
    <div class="background-decoration">
        <div class="decoration-circle circle-1"></div>
        <div class="decoration-circle circle-2"></div>
        <div class="decoration-circle circle-3"></div>
    </div>

    <header class="header">
        <div class="container">
            <div class="logo" onclick="window.location.href='index.html'">
                <span class="logo-icon"><i class="fas fa-globe-americas"></i></span>
                HUAWEI Global Store
            </div>
            <div>
                <a href="index.html">首页</a>
                <a href="product-list.html">新品</a>
                <a href="support.html">服务支持</a>
            </div>
        </div>
    </header>

    <div class="login-container">
        <div class="login-box">
            <h2>用户登录</h2>
            
            <div class="input-group">
                <i class="fas fa-user"></i>
                <input type="text" id="username" placeholder="请输入用户名/邮箱">
            </div>
            <div class="error-message" id="usernameError"></div>

            <div class="input-group">
                <i class="fas fa-lock"></i>
                <input type="password" id="password" placeholder="请输入密码">
            </div>
            <div class="error-message" id="passwordError"></div>

            <!-- 身份选择模块 -->
            <div class="identity-select">
                <div class="identity-option">
                    <input type="radio" name="identity" id="identityUser" value="user" checked>
                    <label for="identityUser">普通用户</label>
                </div>
                <div class="identity-option">
                    <input type="radio" name="identity" id="identityAdmin" value="admin">
                    <label for="identityAdmin">管理员</label>
                </div>
            </div>
            <div class="identity-error" id="identityError">请选择登录身份</div>

            <div class="checkbox-container">
                <div>
                    <input type="checkbox" id="rememberMe">
                    <label for="rememberMe">记住我</label>
                </div>
                <a href="forgot-password.html" class="forgot-password">忘记密码?</a>
            </div>

            <button class="btn" id="loginButton">登录</button>

            <div class="divider"><span>或使用以下方式登录</span></div>
            <div class="social-login">
                <div class="social-btn wechat">
                    <i class="fab fa-weixin"></i>
                </div>
                <div class="social-btn qq">
                    <i class="fab fa-qq"></i>
                </div>
                <div class="social-btn weibo">
                    <i class="fab fa-weibo"></i>
                </div>
            </div>

            <div class="register-link">
                还没有账号? <a href="register.html">立即注册</a>
            </div>
        </div>
    </div>

    <!-- 登录成功提示 -->
    <div class="login-success" id="loginSuccess">
        <div class="success-content">
            <div class="success-icon"><i class="fas fa-check-circle"></i></div>
            <h3>登录成功!</h3>
            <p id="successDesc">您现在可以使用购物车和所有会员功能</p>
            <button class="continue-btn" id="continueButton">继续</button>
        </div>
    </div>

    <script>
        window.onload = function() {
            // 自动填充记住的账号
            const savedUsername = localStorage.getItem('username');
            const savedPassword = localStorage.getItem('password');
            const savedIdentity = localStorage.getItem('identity') || 'user';
            
            if (savedUsername && savedPassword) {
                document.getElementById('username').value = savedUsername;
                document.getElementById('password').value = savedPassword;
                document.getElementById('rememberMe').checked = true;
                // 恢复上次选择的身份
                document.getElementById(`identity${savedIdentity.charAt(0).toUpperCase() + savedIdentity.slice(1)}`).checked = true;
            }

            const loginButton = document.getElementById('loginButton');
            const usernameInput = document.getElementById('username');
            const passwordInput = document.getElementById('password');
            const usernameError = document.getElementById('usernameError');
            const passwordError = document.getElementById('passwordError');
            const identityError = document.getElementById('identityError');
            const loginSuccess = document.getElementById('loginSuccess');
            const continueButton = document.getElementById('continueButton');
            const successDesc = document.getElementById('successDesc');

            // 不同角色的默认账号密码配置
            const accountConfig = {
                user: { username: 'user', password: '123456' },  // 普通用户默认账号密码
                admin: { username: 'admin', password: '123456' } // 管理员默认账号密码
            };

            // 输入验证函数
            function validateInputs() {
                let isValid = true;
                const username = usernameInput.value.trim();
                const password = passwordInput.value.trim();
                const selectedIdentity = document.querySelector('input[name="identity"]:checked')?.value;

                // 清空之前的错误信息
                usernameError.style.display = 'none';
                passwordError.style.display = 'none';
                identityError.style.display = 'none';

                // 用户名验证
                if (!username) {
                    usernameError.textContent = '请输入用户名或邮箱';
                    usernameError.style.display = 'block';
                    isValid = false;
                }

                // 密码验证
                if (!password) {
                    passwordError.textContent = '请输入密码';
                    passwordError.style.display = 'block';
                    isValid = false;
                } else if (password.length < 6) {
                    passwordError.textContent = '密码长度不能少于6位';
                    passwordError.style.display = 'block';
                    isValid = false;
                }

                // 身份选择验证
                if (!selectedIdentity) {
                    identityError.style.display = 'block';
                    isValid = false;
                }

                return isValid;
            }

            // 登录函数
            function performLogin() {
                const username = usernameInput.value.trim();
                const password = passwordInput.value.trim();
                const rememberMe = document.getElementById('rememberMe').checked;
                const selectedIdentity = document.querySelector('input[name="identity"]:checked').value;

                if (!validateInputs()) {
                    return;
                }

                // 显示加载状态
                loginButton.classList.add('btn-loading');

                // 模拟网络请求延迟
                setTimeout(() => {
                    // 验证对应身份的账号密码
                    const targetAccount = accountConfig[selectedIdentity];
                    if (username === targetAccount.username && password === targetAccount.password) {
                        // 存储登录状态和用户信息
                        localStorage.setItem('isLoggedIn', 'true');
                        localStorage.setItem('currentUser', username);
                        localStorage.setItem('userIdentity', selectedIdentity);

                        // 记住账号密码（如果勾选）
                        if (rememberMe) {
                            localStorage.setItem('username', username);
                            localStorage.setItem('password', password);
                            localStorage.setItem('identity', selectedIdentity);
                        } else {
                            localStorage.removeItem('username');
                            localStorage.removeItem('password');
                            localStorage.removeItem('identity');
                        }

                        // 根据身份设置成功提示和跳转链接
                        let redirectUrl = '';
                        if (selectedIdentity === 'admin') {
                            successDesc.textContent = '您已进入管理员后台，将为您跳转...';
                            redirectUrl = 'background.html'; // 管理员跳转后台
                        } else {
                            successDesc.textContent = '您现在可以使用购物车和所有会员功能';
                            redirectUrl = 'index.html'; // 普通用户跳转首页
                        }

                        // 显示成功动画
                        loginSuccess.style.opacity = '1';
                        loginSuccess.style.pointerEvents = 'all';
                        document.querySelector('.success-content').style.transform = 'scale(1)';

                        // 绑定继续按钮跳转事件
                        continueButton.onclick = function() {
                            window.location.href = redirectUrl;
                        };

                        // 3秒后自动跳转
                        setTimeout(() => {
                            window.location.href = redirectUrl;
                        }, 3000);

                    } else {
                        // 登录失败处理
                        passwordError.textContent = '用户名或密码错误，请重试';
                        passwordError.style.display = 'block';
                    }

                    // 隐藏加载状态
                    loginButton.classList.remove('btn-loading');
                }, 1500);
            }

            // 登录按钮点击事件
            loginButton.addEventListener('click', (event) => {
                event.preventDefault();
                performLogin();
            });

            // 回车键登录
            document.addEventListener('keydown', (event) => {
                if (event.key === 'Enter') {
                    performLogin();
                }
            });

            // 社交登录按钮点击事件
            document.querySelectorAll('.social-btn').forEach(btn => {
                btn.addEventListener('click', () => {
                    alert('该登录方式暂未开放，请使用账号密码登录');
                });
            });
        };
    </script>
</body>
</html>
